package com.luocc.ccdemo.vm

import android.app.Application
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.luocc.ccdemo.db.BlogRepository
import com.luocc.ccdemo.entity.Result
import kotlinx.coroutines.launch
private const val TAG = "BlogViewModel"
class BlogViewModel(application: Application) : AndroidViewModel(application) {

    private val mRepository = BlogRepository()

    private val mBlogList: MutableLiveData<Result<Bundle>> = MutableLiveData()

    fun getBlog(pagination: Int = 0, pageSize: Int = -1) {
        viewModelScope.launch {
            try {
                val result = mRepository.getBlog(pagination, pageSize)
                mBlogList.value = result
            } catch (e: Exception) {
                e.printStackTrace()
                mBlogList.value = Result()
            }
        }
    }

    fun getBlogList(): MutableLiveData<Result<Bundle>> {
        return mBlogList
    }
}